//
//  HeadSculpture_ViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 16/9/6.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "HeadSculpture_ViewController.h"

@interface HeadSculpture_ViewController ()

@property (nonatomic, strong) UIImageView * image_Pic;

@end

@implementation HeadSculpture_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    UIView * view_Top = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    view_Top.backgroundColor = [UIColor colorWithRed:20/255.0 green:20/255.0 blue:20/255.0 alpha:1.0];
    [self.view addSubview:view_Top];
    
    //左取消
    UIButton * btn_Cancel = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_Cancel.frame = CGRectMake(10, 10, 50, 40);
    [btn_Cancel setTitle:@"取消" forState:(UIControlStateNormal)];
    [btn_Cancel setTitleColor:[UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0] forState:(UIControlStateNormal)];
    btn_Cancel.titleLabel.font = [UIFont systemFontOfSize:17];
    [view_Top addSubview:btn_Cancel];
    [btn_Cancel addTarget:self action:@selector(btn_CancelAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //右保存
    UIButton * btn_Save = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_Save.frame = CGRectMake(SCREEN_WIDTH - 10 - 50, 10, 50, 40);
    [btn_Save setTitle:@"保存" forState:(UIControlStateNormal)];
    [btn_Save setTitleColor:[UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0] forState:(UIControlStateNormal)];
    btn_Save.titleLabel.font = [UIFont systemFontOfSize:17];
    [view_Top addSubview:btn_Save];
    [btn_Save addTarget:self action:@selector(btn_SaveAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //中间1/1
    UILabel * lbl_Top = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 - 50, 23, 100, 15)];
    lbl_Top.text = @"1/1";
    lbl_Top.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
    lbl_Top.textAlignment = NSTextAlignmentCenter;
    lbl_Top.font = [UIFont systemFontOfSize:17];
    [view_Top addSubview:lbl_Top];
}

//左取消
- (void )btn_CancelAction:(UIButton *)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

//右保存
- (void )btn_SaveAction:(UIButton *)sender
{
//    NSLog(@"点击保存在本地");
    
    UIImageWriteToSavedPhotosAlbum(self.image_Pic.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}

//tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];

    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor blackColor];
    
    CGFloat length_x = (SCREEN_HEIGHT - SCREEN_WIDTH) / 2;
    
    //图片
    self.image_Pic = [[UIImageView alloc] initWithFrame:CGRectMake(0, length_x, SCREEN_WIDTH, SCREEN_WIDTH)];
    [self.image_Pic sd_setImageWithURL:[NSURL URLWithString:@"http://pic49.nipic.com/file/20140928/4949133_154705706000_2.jpg"] placeholderImage:[UIImage imageNamed:self.str_image]];
    [self.view addSubview:self.image_Pic];
}

#pragma mark - 保存图片
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    [SVProgressHUD setMinimumDismissTimeInterval:0.9f];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setBackgroundColor:[UIColor colorWithRed:20/255.0 green:20/255.0 blue:20/255.0 alpha:0.8f]];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD showSuccessWithStatus:@"保存成功"];
}


@end
